<?php
/**
 * Zeed Platform Project
 * Based on Zeed Framework & Zend Framework.
 *
 * LICENSE
 * http://www.zeed.com.cn/license/
 *
 * @category   Zeed
 * @package    Zeed_ChangeMe
 * @subpackage ChangeMe
 * @copyright  Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
 * @author     Zeed Team (http://blog.zeed.com.cn)
 * @since      Sep 29, 2010
 * @version    SVN: $Id: $
 */

abstract class ShellAbstract extends Zeed_Controller_Action
{
    /**
     * 是否跳过开启 XSS 过滤，如果设置为 true，那么该控制器下所有方法都将不启动 XSS 过滤
     * 如果设置为 array ，所有在 array 中的方法都将不启动 XSS 过滤
     *
     * @var boolean|array
     */
    protected $_skip_xss_clean = true;
    
    /**
     * 是否跳过开启 Session，如果设置为 true，那么该控制器下所有方法都将不启动 Session
     * 如果设置为 array ，所有在 array 中的方法都将不启动 Session
     *
     * @var boolean|array
     */
    protected $_skip_session_create = true;
    
    protected $_debug = false;
    
    protected function _init()
    {
        // if (! defined('ZEED_IN_CONSOLE')) {
        //     die('404 NOT FOUND');
        // }
        
        /* Allow the script to hang around waiting for connections. */
        set_time_limit(0);
        
        /* Turn on implicit output flushing so we see what we're getting
         * as it comes in. */
        ob_implicit_flush();
        
        $parsedRequestUrl = parse_url($_SERVER['REQUEST_URI']);
        $querys = isset($parsedRequestUrl['query']) ? $this->_parseQueryString($parsedRequestUrl['query']) : array();
        $this->_debug = isset($querys['d']) ? true : false;
        
        if (!$this->_debug) {
            Com_Event::add('system.flush', 'Event_FlushClean');
        }
    }
    
    protected function _parseQueryString($str) {
        $op = array();
        $pairs = explode("&", $str);
        
        foreach ($pairs as $pair) {
            $explodedPair = explode("=", $pair);
            
            if (is_array($explodedPair)) {
                if (count($explodedPair) == 2) {
                    list($k, $v) = array_map("urldecode", $explodedPair);
                    $op[$k] = $v;
                } elseif (count($explodedPair) == 1) {
                    $k = urlencode(array_pop($explodedPair));
                    $op[$k] = '';
                }
            }
        }
        
        return $op; 
    }
}

// End ^ Native EOL ^ encoding
